#include<iostream>
using namespace std;
struct tx
{
	int yw;
	int sx;
	int waiyu;
	int sum;
};
int main()
{
	tx cj[1000];
	int n, k = 0;
	cin >> n;
	for (int i = 0; i < n; i++)
	{
		cin >> cj[i].yw >> cj[i].sx >> cj[i].waiyu;
		cj[i].sum = cj[i].sx + cj[i].yw + cj[i].waiyu;
	}
	for (int i = 0; i < n; i++)
	{
		for (int j = i + 1; j < n; j++)
		{
			if ((cj[i].yw - cj[j].yw <= 5 && cj[i].yw - cj[j].yw >= -5) && (cj[i].sx - cj[j].sx <= 5 && cj[i].sx - cj[j].sx >= -5) && (cj[i].waiyu - cj[j].waiyu <= 5 && cj[i].waiyu - cj[j].waiyu >= -5))
			{
				if (cj[i].sum - cj[j].sum <= 10 && cj[i].sum - cj[j].sum >= -10)
				{
					k++;
				}

			}

		}
	}
	cout << k << endl;
	system("pause");
	return 0;
}
